using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using Gameplay;

public class MoveToPatrolPoint : Action
{
    public string PatrolPointName = "PatrolPos";
	private GameObject _patrolPos;
    private int _patrolIndex;
    private Character _character;

    public override void OnStart()
	{
        _character = GetComponent<Character>();
        _patrolPos = GameObject.Find(PatrolPointName);
        _patrolIndex = 0;
    }

	public override TaskStatus OnUpdate()
	{
		if (_patrolPos.transform.childCount > 0) 
		{
            if (_character.MoveToTarget(_patrolPos.transform.GetChild(_patrolIndex).position))
            {
                _patrolIndex++;
              
                if (_patrolIndex > _patrolPos.transform.childCount - 1)
                {
                    _patrolIndex = 0;
                }
            }
            return TaskStatus.Running;
        
            
            
        }
		else 
		{
			return TaskStatus.Failure;
		}
		
	}
}